#!/usr/bin/env node

const http = require('https'),
      url = require('url'),
      log = console.log;

let addr = process.argv[2] || 'https://sample.wangding.co/web/one-div.html',
//url.parse可以将一个完整的URL地址分为很多部分，例如host,pathname等
//encodeURI()函数把字符串作为URI进行编码
    options = url.parse(global.encodeURI(addr));
:wq

    options.headers = {
      'User-Agent':'01-my-curl.js'
    };

http.get(addr,(res)=> {
  log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);
  log(res.headers);
  log();
  res.pipe(process.stdout)
})
